<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<title>51微贷</title>
		<link rel="stylesheet" type="text/css" href="../css/reset.css">
		<link rel="stylesheet" type="text/css" href="../css/common.css">
		<link rel="stylesheet" type="text/css" href="../css/icomoon/style.css">
		<link rel="stylesheet" type="text/css" href="../css/listloading.base.css">
		<link rel="stylesheet" type="text/css" href="../css/listloading.min.css">
		<script type="text/javascript" src="../js/rem.js"></script>
		<script type="text/javascript" src="../js/zepto.min.js"></script>
		<script type="text/javascript" src="../js/require.js"></script>
	</head>
	<body>
		<div class="m-message">
			<h3 class="header f-pr">
				<span>消息中心</span>
				<i class="icon-angle-left f-pa"></i>
			</h3>
			<div class="tabs">
				<a class="tab cur" data-id="1"><span>公告</span></a>
				<a class="tab" data-id="2"><span>提醒</span></a>
			</div>
			<div id="wrapper" style="overflow: hidden;">
				<div id="scroller">
					<div id="item1">
						<ul class="message-list"></ul>
						<div class="nodata hide">
							<p class="img"><img src="../images/nodata-3.png"></p>
							<p class="text">暂无消息</p>
							<!-- <a class="refresh">刷新</a> -->
						</div>
					</div>
					<div id="item2" class="hide">
						<ul class="message-list"></ul>
						<div class="nodata hide">
							<p class="img"><img src="../images/nodata-3.png"></p>
							<p class="text">暂无消息</p>
							<!-- <a class="refresh">刷新</a> -->
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>

		<script type="text/javascript">
			require.config({
				paths: {
					'iscroll': '../js/iscroll.min',
					'listloading': '../js/listloading.min',
					'encryption': '../js/md5.min'
				}
			});

			mui.plusReady(function(){
				require(['iscroll', 'listloading', 'encryption'], function(){
					var md5 = require('encryption');
					var Listloading = require('listloading');
					var page_index = 1, page_size = 6, page_count = 10;

					$('#wrapper, .listloadingClass').height($(window).height() - 20);

					var buildHtml = function(item, obj){
						var result = '';
						result += '<li data-id="' + item.id + '">';
						result += '<p>' + item.title + '<p>';
						result += '<p class="time">' + item.time + '</p>';
						result += '</li>';
						$(obj).append(result);
					};

					var messageList = {
						init: function(cb, flag, page_index, page_size){
							this.notice(cb, flag, page_index, page_size);
							this.message(cb, flag, page_index, page_size);
						},

						notice: function(cb, flag, page_index, page_size){
							if(flag){
								return cb(flag);
							}else{
								mui.ajax(base + 'account/notice', {
									type: 'get',
									data: {
										'user': plus.storage.getItem('user_id'),
										'page_index': page_index,
										'page_size': page_size
									},
									dataType: 'json',
									headers: sign(md5),
									success: function(data){
										var list = data.list, page_index = data.page_index, page_count = data.page_count;
										
										if(data.page_index == 1){
											$('#item1 ul').empty();
										}
										if(list.length > 0){
											for(var i = 0, len = list.length; i < len; i++){
												buildHtml(list[i], '#item1 ul');
											}
										}else{
											$('#item1 .nodata').removeClass('hide');
											$('body').addClass('bg');
										}
										
										cb(flag);
									},
									error: function(data){
										console.error(data.message);
									}
								});
							}
						},

						message: function(cb, flag, page_index, page_size){
							if(flag){
								return cb(flag);
							}else{
								mui.ajax(base + 'account/message', {
									type: 'get',
									data: {
										'user': plus.storage.getItem('user_id'),
										'page_index': page_index,
										'page_size': page_size
									},
									dataType: 'json',
									headers: sign(md5),
									success: function(data){
										var list = data.list, page_index = data.page_index, page_count = data.page_count;
										
										if(data.page_index == 1){
											$('#item2 ul').empty();
										}
										if(list.length > 0){
											for(var i = 0, len = list.length; i < len; i++){
												buildHtml(list[i], '#item2 ul');
											}
										}else{
											$('#item2 .nodata').removeClass('hide');
											$('body').addClass('bg');
										}
										
										cb(flag);
									},
									error: function(data){
										console.error(data.message);
									}
								});
							}
						}
					}

					var listloading = new Listloading('#wrapper', {
						disableTime: true,
						pullUpAction: function(cb){
							var flg = false;
							if(page_index + 1 > page_count){
								flg = true;
							}else{
								page_index++
							}
							return messageList.init(cb, flg, page_index, page_size);
						},
						pullDownAction: function(cb){
							page_index = 1;
							return messageList.init(cb, false, page_index, page_size);
						},
						Realtimetxt: '官人不要，请放开我！',
	        			loaderendtxt: '我是有底线的',
	        			iscrollOptions: {
		                    scrollbars: false   
		                }
					});

					listloading.evt('li', 'tap', function (dom) {
		                var data_id = $(dom).attr('data-id');
						mui.openWindow({url: 'messagedetail.html', extras: {data_id: data_id}});
		                listloading.refresh();
		            });

					$('.icon-angle-left').on('tap', function(){
						mui.back();
					});

				});
			});
		</script>
	</body>
</html>